/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package e.odbo.data.impexp.processor;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.sentence.SentenceFind;
import e.odbo.data.impexp.ImpExpTableProcessor;
import e.odbo.data.impexp.ImpExpManager;
import e.odbo.data.impexp.model.AbstractImpExpTableDefinition;
import e.odbo.data.impexp.model.ImpExpRowDefinition;

/**
 * 这个类主要用于对导入数据与以有数据进行对比，并对检查对象设置相应的标记（新建、更新）
 *
 * @author Administrator
 */
public class ImportObjectStateProcessor extends ImpExpTableProcessor {

    public ImportObjectStateProcessor(ImpExpManager manager) {
        super(manager);
    }

    @Override
    public void process(AbstractImpExpTableDefinition table) {
        SentenceFind exec = table.getExistSentence();
        int[] fieldIndex = table.getListFieldIndexs();
        ImpExpRowDefinition row;
        int rowCount = table.getRowCount();
        for (int rowindex = 0; rowindex < rowCount; rowindex++) {
            row = table.getRow(rowindex);
            Object[] data = row.getDatas();
            try {
                int count = (Integer) exec.find(data);
                if (count > 0)
                    row.setState(ImpExpRowDefinition.STATE_Import_Update);
            } catch (BasicException e) {
                e.printStackTrace();
                row.setState(ImpExpRowDefinition.STATE_Ignore);
            }
            System.out.println("ID:" + data[0] + "导入态：" + (row.getState() == ImpExpRowDefinition.STATE_Import_Update ? "更新" : "插入"));
        }
    }

}
